##############################################################
## MOD Title:          Switch Style From URL
## MOD Author:         spooky2280 < webmaster@christianfecteau.com > (Christian Fecteau) http://portfolio.christianfecteau.com/
## MOD Description:    This MOD interprets a style=x argument in the URL and displays your board using the theme
##                     with id=x in the db. All links in the page have the style=x argument appended.
##                     A Style Switcher (using a frameset) is included with the MOD.
##                     See the MOD in action: http://christianfecteau.com/ssu
##
## MOD Version:        1.0.0
##
## Installation Level: Easy
## Installation Time:  5 Minutes
##
## Files To Edit:      3
##      common.php
##      includes/functions.php
##      includes/sessions.php
##
## Included Files:     styles.html
##                     styles.php
##
##############################################################
## For Security Purposes, Please Check: http://www.phpbb.com/mods/ for the
## latest version of this MOD. Downloading this MOD from other sites could cause malicious code
## to enter into your phpBB Forum. As such, phpBB will not offer support for MOD's not offered
## in our MOD-Database, located at: http://www.phpbb.com/mods/
##############################################################
## Author Notes:
##
## This MOD uses the superglobals $_GET and $_POST introduced in PHP 4.1.0
## You will need to adapt the code for earlier versions of PHP:
## use $HTTP_GET_VARS and $HTTP_POST_VARS and declare them as globals within functions.
##
## The URL for the style switcher is "http://www.example.com/yourboard/styles.html"
## If you try to load "http://www.example.com/yourboard/styles.php", there is a JavaScript
## redirection to "http://www.example.com/yourboard/styles.html"
##
## This MOD is like the Styles Demo at phpBB.com except that you can also submit and register.
## In other words, the board is fully functional while you're in the demo (a frameset).
## You don't actually need the demo. The style is changed if the style=x argument is found
## in the URL, whether you're in the frameset or not. But in the demo, the MOD uses JavaScript
## to keep you at the exact same URL when you switch style, instead of bringing you back to the
## index page like at phpBB.com
##
## The 2 included files are indeed optional. You can manually add
## a style=x argument to the URL and the MOD will display the style
## with id=x in the db. And all links in the page will have the
## argument appended so the user keeps the style from page to
## page. Only the admin and moderator links don't have the argument
## appended.
##
## This program is free software; you can redistribute it and/or modify
## it under the terms of the GNU General Public License as published by
## the Free Software Foundation; either version 2 of the License, or
## (at your option) any later version.
##
## Credits must be given with my full name (Christian Fecteau)
## and a link to my portfolio: http://portfolio.christianfecteau.com/
##
## Removal or alteration of this notice is strongly prohibited.
##
##############################################################
## MOD History:
##
##   2005-02-13 - Version 1.0.0
##      - style argument is not appended anymore upon submission of profile
##      - Added a warning in the Author Notes about versions of PHP
##        prior to 4.1.0 and the use of the superglobals $_GET and $_POST in this MOD.
##      - Added a commented TITLE element in styles.php and styles.html:
##        <!-- title>Uncomment and put the title that you want</title -->
##
##   2005-02-12 - Version 0.1.0 BETA
##      - First release, tested with phpBB 2.0.11 and EasyMod 0.1.13
##
##############################################################
## Before Adding This MOD To Your Forum, You Should Back Up All Files Related To This MOD
##############################################################

#
#-----[ COPY ]------------------------------------------
#
copy styles.html to styles.html
copy styles.php to styles.php
#
#-----[ OPEN ]------------------------------------------
#
common.php
#
#-----[ FIND ]------------------------------------------
#
# around line 177
#
$gen_simple_header
#
#-----[ AFTER, ADD ]------------------------------------------
#

//---------start mod: Switch Style From URL-------------------------
$ssu_get = false;
//---------fin mod: Switch Style From URL-------------------------

#
#-----[ OPEN ]------------------------------------------
#
includes/functions.php
#
#-----[ FIND ]------------------------------------------
#
# around line 227
#
global $nav_links
#
#-----[ IN-LINE FIND ]------------------------------------------
#
global
#
#-----[ IN-LINE AFTER, ADD ]------------------------------------------
#
 $ssu_get, $db,
#
#-----[ FIND ]------------------------------------------
#
# around line 267
#
!$board_config['override_user_style']
#
#-----[ BEFORE, ADD ]------------------------------------------
#

	//---------start mod: Switch Style From URL-------------------------
	if (isset($_GET['style']))
	{
		$sql = "SELECT themes_id, template_name
			FROM " . THEMES_TABLE . " 
			ORDER BY template_name";

		if(!$result = $db->sql_query($sql))
		{
			message_die(GENERAL_ERROR, "Could not get style information!", "", __LINE__, __FILE__, $sql);
		}

		$style_rowset = $db->sql_fetchrowset($result);

		foreach ($style_rowset as $ssu_sel)
		{
			if (strval($ssu_sel['themes_id']) === strval($_GET['style']))
			{
				$board_config['default_style'] = strval($ssu_sel['themes_id']);
				$ssu_get = strval($ssu_sel['themes_id']);
				break;
			}
			$ssu_get = false;
		}
	}
	//---------fin mod: Switch Style From URL-------------------------

#
#-----[ IN-LINE FIND ]------------------------------------------
#
!$board_config['override_user_style']
#
#-----[ IN-LINE AFTER, ADD ]------------------------------------------
#
 && !$ssu_get
#
#-----[ FIND ]------------------------------------------
#
# around line 324
#
$row['template_name']
#
#-----[ AFTER, ADD ]------------------------------------------
#
	$board_config['ssu_current'] = $row['themes_id'];
#
#-----[ OPEN ]------------------------------------------
#
includes/sessions.php
#
#-----[ FIND ]------------------------------------------
#
# around line 390
#
global $SID
#
#-----[ IN-LINE FIND ]------------------------------------------
#
global
#
#-----[ IN-LINE AFTER, ADD ]------------------------------------------
#
 $ssu_get,
#
#-----[ FIND ]------------------------------------------
#
# around line 397
#
return $url;
#
#-----[ BEFORE, ADD ]------------------------------------------
#

	//---------start mod: Switch Style From URL-------------------------
	if (($ssu_get) && !preg_match('#style=#', $url) && !isset($_POST['style']))
	{
		$url .= ((strpos($url, '?') != false) ? (($non_html_amp) ? '&' : '&amp;') : '?') . 'style=' . $ssu_get;
	}
	//---------fin mod: Switch Style From URL-------------------------

#
#-----[ SAVE/CLOSE ALL FILES ]------------------------------------------
#
# EoM